
export default {
    state: {
        isLoggedIn: false,
        userInfo: null,
        isAdmin: false,
    },
    getters: {
        getUserInfo(state) {
            return state.userInfo;
        },
        getIsLoggedIn(state) {
            return state.isLoggedIn;
        }
    },
    mutations: {
        login(state, user) {
            state.isLoggedIn = user ? true : false;
            state.isAdmin = user?.roles == 'admin' ? true : false;
            state.userInfo = user ? user : null;
        },
        logout(state) {
            state.isLoggedIn = false;
            state.userInfo = null;
        },
    },
    actions: {
        login({ commit }, user) {
            commit('login', user);
        },
        async logout({ commit }) {
            await api.logout();
            commit('logout');
        },
    },
    modules: {

    }
}